<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv=Content-Type content="text/html; charset=utf-8">
    <title>发布问题 - 小乖乖问答系统</title>
    <link rel="icon" href="/favicon.ico">
    <link rel="stylesheet" href="/css/publish.css">
    <link rel="stylesheet" href="/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="/css/markdown/editormd.min.css"/>
    <link rel="stylesheet" href="/css/bootstrap-theme.min.css"/>
    <script src="/js/jquery-3.4.1.js" type="application/javascript"></script>
    <script src="/js/bootstrap.min.js" type="application/javascript"></script>
    <script src="/layer/layer.js" type="application/javascript"></script>
    <script src="https://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
    <script src="/js/markdown/editormd.min.js" type="application/javascript"></script>
</head>
<body class="main-img">
<nav th:insert="~{common/head :: comment_header}">

</nav>
<div class="container-fluid publish">
    <div class="row">
        <div class="col-lg-9 col-md-12 col-sm-12 col-xs-12">
            <h2><span class="glyphicon glyphicon-plus" aria-hidden="true"></span>&nbsp;发起</h2>
            <hr/>
            <form action="/publish" method="post">
                <input type="hidden" th:value="${questionId}" name="questionId">
                <div class="form-group">
                    <label for="questionTitle">问题标题（简单扼要）：</label>
                    <input type="text" th:value="${questionTitle}" class="form-control" id="questionTitle"
                           name="questionTitle" placeholder="问题标题..." autocomplete="off"/>
                </div>

                <div class="form-group" id="question-editor">
                    <label for="description">问题补充（必填，请参照右侧提示）：</label>
                    <textarea name="description" th:text="${description}" id="description" cols="30" rows="10"
                              class="form-control" style="display: none;"></textarea>
                </div>
                <script type="text/javascript">
                    $(function () {
                        var editor = editormd("question-editor", {
                            width: "100%",
                            height: 350,
                            path: "/js/markdown/lib/",
                            delay: 0,
                            watch: false,
                            placeholder: "输入您的问题描述吧",
                            imageUpload: true,
                            imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
                            imageUploadURL: "/file/upload"
                        });
                    });
                </script>
                <div class="form-group">
                    <label for="tag">添加标签：</label>
                    <input type="text" class="form-control" th:value="${tag}" id="tag" name="tag"
                           placeholder="输入标签，以'，'号分割 " autocomplete="off" readonly="true" onclick="btnTag();"/>
                    <div>
                        <!--                        标签库-->
                        <div style="display: none;" id="tags">
                            <!-- Nav tabs -->
                            <ul class="nav nav-tabs" role="tablist">
                                <li role="presentation" th:each="tag,tagindex : ${tags}"
                                    th:class="${tagindex.first ? 'active' : '' }">
                                    <a th:href="@{'#'+${tag.categoryName}}" aria-controls="home" role="tab"
                                       data-toggle="tab" th:text="${tag.categoryName}">
                                    </a>
                                </li>
                            </ul>
                            <!-- Tab panes -->
                            <div class="tab-content">
                                <div role="tabpanel" th:each="tag,tagindex : ${tags}"
                                     th:id="${tag.categoryName}" style="padding-top: 10px;"
                                     th:class="${tagindex.first ? 'active tab-pane' : 'tab-pane' }">
                                    <span th:each="tagMsg : ${tag.tags}"
                                          style="display: inline-block;margin: 5px 5px;white-space: normal!important;"
                                          class="glyphicon glyphicon-tags label label-info"
                                          th:onclick="selectTag([[${tagMsg}]])">
                                        <span th:text="${tagMsg}">Java</span>
                                     </span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="container-fluid">
                    <div class="row">

                        <div class="alert alert-warning alert-dismissible col-lg-9 col-md-12 col-sm-12 col-xs-12"
                             role="alert" th:if="${error} != null"
                             style="height: 40px;margin-bottom: 0px !important;line-height: 10px !important;">
                            <button type="button" class="close" data-dismiss="alert" aria-label="Close"
                                    style="margin-top: -3px !important;">
                                <span aria-hidden="true">&times;</span>
                            </button>
                            <strong>Warning!</strong>&nbsp; <span th:text="${error}"></span>
                        </div>

                        <div class="col-lg-3 col-md-12 col-sm-12 col-xs-12">
                            <!-- Indicates a successful or positive action -->
                            <button type="submit" class="btn btn-success button" style="margin-bottom: 10px;">发布
                            </button>
                        </div>

                    </div>
                </div>

            </form>
        </div>
        <div class="col-lg-3 col-md-12 col-sm-12 col-xs-12">
            <h3>问题发起指南</h3>
            <ul>
                <li>问题标题： 请用精简的语言描述您发布的问题，不超过25个字</li>
                <li>问题补充： 详细补充您的问题内容，并确保问题描述清晰直观，并提供一些相关的资料</li>
                <li>选择标签： 选择一个或者多个合适的标签，标签之间用" ， "隔开每个标签不超过10个字</li>
            </ul>
        </div>
    </div>
</div>
<nav th:insert="~{common/footer :: comment_footer}"></nav>
</body>
<script>
    function selectTag(value) {
        var previous = $("#tag").val();

        if (previous.indexOf(value) == -1) {
            if (previous) {
                $("#tag").val(previous + ',' + value);
            } else {
                $("#tag").val(value);
            }
        } else {
            layer.msg(value + "标签已添加，请勿重复添加", {icon: 4});
        }
    }

    function btnTag() {
        $("#tags").show();
    }
</script>
</html>